package com.itheima.test;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/*
接受不断的接收数据
 */
public class JieshouClient {
    public static void main(String[] args) throws IOException {
        //创建接受对象
        DatagramSocket ds = new DatagramSocket(8888);

        //创建数据对象
        byte[] bytes = new byte[1024 * 64];
        while (true) {
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
            //接受
            ds.receive(dp);

            //打印数据
            String s = new String(bytes, 0, dp.getLength());
            System.out.println(s);
            if("886".equals(s)){
                break;
            }
        }


        //释放资源
        ds.close();


    }

}
